var app = sm("do_App");
var page = sm("do_Page");
var hashdata = mm("do_HashData");
var common = require("common");
var nf = sm("do_Notification");
var http = require("helper/http");
var urlPub = require("url/pub");
var httpUrl = urlPub.url.comment.doAdd;
var communityUtil = require("helper/community");

var bizzId = null; //业务类型对应ID
var bizzType = null; //业务类型
var beCommentedId = null; //被回复的评论ID
var beCommentedName = null;//被回复的用户名
var content = ui("content");
var btnSubmit = ui("btnSubmit");
content.setFocus(true);

//引入公共heander
var headerAout = ui("headerSendComment");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);

var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
    app.closePage()
});

var header = ui("header");
header.bindData(hashdata);
hashdata.addData({
    "labelTitle" : "回复",
    "labelNext": "发送"
});
header.refreshData();

//andriod返回键
page.on("back", function() {
    app.closePage();
});

//获取上一个页面传入的参数
page.on("loaded", function(){
	var params = page.getData();
	bizzId = params.bizzId;
	bizzType = params.bizzType;
	beCommentedId = params.beCommentedId;
	beCommentedName = params.beCommentedName;
	if(params.beCommentedName){
		content.hint = content.hint+beCommentedName;
	}
});

//提交
btnSubmit.on("touch", function(){
	if(content.text.length == 0){
		nf.toast("评论内容不能为空");
		return;
	}
	submit();
});

function submit(){
	var addParams = {
            bizzId:bizzId,
            bizzType:bizzType,
			content:content.text,
			beCommentedId:beCommentedId,
			communityId:communityUtil.communityVisitId()
		};
	btnSubmit.enabled = false;
	http.post(httpUrl,addParams,function(data){
		app.closePage({"comment_add":true});
	});
}